package com.ruoyi.web.controller.ring.app;

import cn.hutool.core.convert.Convert;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.bean.Builder;
import com.ruoyi.ring.domain.RingRelaxFrequency;
import com.ruoyi.ring.domain.RingRelaxInfo;
import com.ruoyi.ring.domain.vo.RelaxFrequencyListVO;
import com.ruoyi.ring.domain.vo.RelaxInfoVO;
import com.ruoyi.ring.service.IRingRelaxFrequencyService;
import com.ruoyi.ring.service.IRingRelaxInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 减压助眠  app
 * @author liuwp
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/ring/app_relax_info")
public class AppRelaxInfoController extends BaseController
{
    @Resource
    private IRingRelaxInfoService ringRelaxInfoService;
    @Resource
    private IRingRelaxFrequencyService ringRelaxFrequencyService;

    /**
     * 查询减压助眠列表  app
     */
    @GetMapping("/query-relax-info-list")
    public AjaxResult queryRelaxInfoList()
    {
        List<RingRelaxInfo> ringRelaxInfos = ringRelaxInfoService.selectRingRelaxInfoList(new RingRelaxInfo());
        List<RelaxInfoVO> relaxInfoVOS = Convert.toList(RelaxInfoVO.class,ringRelaxInfos);
        return AjaxResult.success(relaxInfoVOS);
    }


    /**
     * 获取减压助眠信息  app
     */
    @GetMapping(value = "/query-relax-info")
    public AjaxResult queryRelaxInfo()
    {
        RingRelaxInfo ringRelaxInfo = ringRelaxInfoService.selectOneRingRelaxInfo(new RingRelaxInfo());
        RelaxInfoVO relaxInfoVO = Convert.convert(RelaxInfoVO.class,ringRelaxInfo);
        return AjaxResult.success(relaxInfoVO);
    }

    /**
     * 获取减压助眠频次集合  app
     * @param relaxType 字典：az_relax_type_zh
     */
    @GetMapping(value = "/query-relax-frequency-list/{relaxType}")
    public AjaxResult queryRelaxFrequencyList(@PathVariable("relaxType") String relaxType)
    {
        List<RingRelaxFrequency> ringRelaxFrequencyList = ringRelaxFrequencyService.selectRingRelaxFrequencyList(Builder.of(RingRelaxFrequency::new).with(RingRelaxFrequency::setRelaxType,relaxType).build());
        List<RelaxFrequencyListVO> relaxFrequencyListVOS = Convert.toList(RelaxFrequencyListVO.class,ringRelaxFrequencyList);
        return AjaxResult.success(relaxFrequencyListVOS);
    }


    /**
     * 减压播放返回秒对应  吸气、呼气节点  app
     * @param minutes 分钟
     */
    @GetMapping(value = "/query-stress-relief-list/{minutes}")
    public AjaxResult stressRelief(@PathVariable("minutes") Integer minutes){
        return AjaxResult.success(ringRelaxInfoService.stressRelief(minutes*60));
    }
    /**
     * 助眠播放返回秒对应  吸气、屏住呼吸、呼气节点  app
     * @param minutes 分钟
     */
    @GetMapping(value = "/query-stress-aid-list/{minutes}")
    public AjaxResult stressAid(@PathVariable("minutes") Integer minutes){
        return AjaxResult.success(ringRelaxInfoService.stressAid(minutes*60));
    }
}
